package wei.zhang.algorithm;

import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;

import java.util.Arrays;
import java.util.Collection;

/**
 * 自定义范围查询 分表
 *  RangeShardingAlgorithm<Long> 这里的泛型是数据类型
 */
public class RangeTableShardingAlgorithm implements RangeShardingAlgorithm<Long> {


    /**
     *
     * @param collection  拿到所有的符合的逻辑表
     * @param rangeShardingValue 参数的上限 和 下限
     * @return
     */
    public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {

        rangeShardingValue.getValueRange().upperEndpoint(); // 上限
        rangeShardingValue.getValueRange().lowerEndpoint(); // 下限
        String logicTableName = rangeShardingValue.getLogicTableName(); //逻辑表
        return Arrays.asList(logicTableName+"_1",logicTableName+"_2");
    }
}
